package com.example.comunicacionactividades;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {

	private EditText textoNombre;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		textoNombre = (EditText)findViewById(R.id.editText1);
		 Button bVerificar =(Button) findViewById(R.id.button1);
	        bVerificar.setOnClickListener(new OnClickListener() {
	          public void onClick(View view) {
	           lanzarVerificar(null);
	          }});
	        }
	
	public void lanzarVerificar(View view){
	      Intent intent = new Intent(this, Verificar.class);
	      intent.putExtra("nombre",textoNombre.getText().toString());
	      startActivityForResult(intent,5);
	    }

	@Override 
	protected void onActivityResult (int requestCode, int resultCode, Intent data){
		if (requestCode==5 && resultCode==RESULT_OK) {
			TextView textoresultado = (TextView)findViewById(R.id.resultado);
			String res = data.getExtras().getString("resultado");
			textoresultado.setText("Resultado: " + res);
		}
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
}


